package com.hurst

class ManagerController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [managerInstanceList: Manager.list(params), managerInstanceTotal: Manager.count()]
    }

    def create = {
        def managerInstance = new Manager()
        managerInstance.properties = params
        return [managerInstance: managerInstance]
    }

    def save = {
        def managerInstance = new Manager(params)
        if (managerInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'manager.label', default: 'Manager'), managerInstance.id])}"
            redirect(action: "list")
        }
        else {
            render(view: "create", model: [managerInstance: managerInstance])
        }
    }

    def delete = {
        def managerInstance = Manager.get(params.id)
        if (managerInstance) {
            try {
                managerInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'manager.label', default: 'Manager'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'manager.label', default: 'Manager'), params.id])}"
                redirect(action: "list")
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'manager.label', default: 'Manager'), params.id])}"
            redirect(action: "list")
        }
    }
}
